
""" 
Target function of target allocation
"""
import numpy.matlib
import numpy as np

# The value of CHROM is 0-7
def  targetalloc(chrom):
    a, b = chrom.shape
    p = np.array([[.87,.52,.11,.78,.72,.69,.94,.72,.36,.28,.27,.74,.24,.78,.45],
                  [.87,.52,.11,.78,.72,.69,.94,.72,.36,.28,.27,.74,.24,.78,.45],
                  [.87,.52,.11,.78,.72,.69,.94,.72,.36,.28,.27,.74,.24,.78,.45],
                  [.87,.52,.11,.78,.72,.69,.94,.72,.36,.28,.27,.74,.24,.78,.45],
                  [.87,.52,.11,.78,.72,.69,.94,.72,.36,.28,.27,.74,.24,.78,.45],
                  [.87,.52,.11,.78,.72,.69,.94,.72,.36,.28,.27,.74,.24,.78,.45],
                  [.62,.87,.70,.22,.80,.42,.43,.90,.13,.95,.18,.19,.12,.61,.35],
                  [.48,.20,.42,.16,.43,.58,.69,.03,.34,.72,.15,.24,.29,.30,.75]])
    w = np.array([.47,.97,.76,.62,.48,.77,.33,.74,.54,.65,.43,.35,.63,.66,.57])

    # Create a floating point number matrix
    chrom2 = np.matlib.zeros((a,15))
    for i in range(0,a):
        for j in range(0,15):
            index = chrom[i,j]
            chrom2[i,j] = p[index,j]
    
    fit = np.dot(chrom2,np.transpose(w))

    for i in range(0,a):
        fit[0,i] = round(float(fit[0,i]),2)

    return fit

